package com.shuoyue.ycgk.ui.papergroups;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.UserTestPaper;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;

public interface CreatePagerSetContract {
    interface View extends BaseView {
        void createPaperSuc(UserTestPaper userTestPaper);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        /**
         * 历年真题和题库里面可以用这个方法
         *
         * @param topicId
         * @param name
         */
        public void createSetPaper(int topicId, String name) {
            apply(model.createPaper(topicId))
                    .subscribe(new ApiSubscriber<Optional<UserTestPaper>>(mView, this,true ) {
                        @Override
                        public void onNext(Optional<UserTestPaper> listOptional) {
                            super.onNext(listOptional);
                            UserTestPaper userTestPaper = listOptional.getIncludeNull();
                            if (userTestPaper != null) {
                                userTestPaper.setName(name);
                                mView.createPaperSuc(userTestPaper);
                            }
                        }
                    });
        }

    }

    class Model extends BaseModel {
        /**
         * 历年真题和题库里面可以用这个方法
         *
         * @param topicId
         * @return
         */
        Observable<BaseResult<UserTestPaper>> createPaper(int topicId) {
            return RetrofitClient.getInstance().getApi().getSetPaper(topicId);
        }

    }
}
